package br.com.ordersys.web.services;

import org.springframework.stereotype.Service;

import br.com.ordersys.framework.restlayer.RestCall;
import br.com.ordersys.framework.restlayer.RestCallContext;

@Service("asynctest")
public class AsyncTest implements IAsyncTest {

	@RestCall(async=true,asyncStatusDetailClass=AsyncDetail.class)
	@Override
	public void doTest() {
		AsyncDetail ad = (AsyncDetail) RestCallContext.get().getAsyncCallInfo().getStatusDetail();
		
		for(int i = 0; i < 100 ; i++){
			if(RestCallContext.get().getAsyncCallInfo().isCanceled()){
				System.out.println("Canceled async call");
				break;
			}
			System.out.println("Async call: " + i);
			ad.setNumero(i);
			ad.setDate(System.currentTimeMillis());
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
